// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/daguan/api/DaguanProgramApi'

import ComClass from '@api/ComQuery'
import OneClass from '@api/daguan/model/DaguanProgramReq'
import EditClass from '@api/daguan/model/DaguanProgramPublishReq'
import PassClass from '@api/daguan/model/DaguanProgramCommonReq'
import BaseClass from '@api/daguan/model/DaguanProgramDto'

const RejClass = PassClass

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'dto']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async getOne(one, TIP = '查询单项') {
    const DTO = CORE.grpcDTO(OneClass, one, COM, BASE)
    const resp = await CORE.grpc(TIP, CLIENT, 'daguanProgramQuery', DTO)
    return (resp.dto || [])[0] || one
  },
  transOne(obj) {
    obj.terminalSnStr = obj.terminalSnValues.join(', ')
    return obj
  },

  // —————————————————————————————— 修改 —————————————————————————————— //

  async edit(one, TIP = '修改') {
    const DTO = CORE.grpcDTO(EditClass, one)
    await CORE.grpc(TIP, CLIENT, 'daguanProgramPublish', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 通过 —————————————————————————————— //

  async pass({ id }, TIP = '通过') {
    const DTO = CORE.grpcDTO(PassClass, { id })
    await CORE.grpc(TIP, CLIENT, 'daguanProgramAudit', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 拒绝 —————————————————————————————— //

  async rej({ id }, TIP = '拒绝') {
    const DTO = CORE.grpcDTO(RejClass, { id })
    await CORE.grpc(TIP, CLIENT, 'daguanRevocation', DTO)
    return CORE.grpcOK(TIP)
  },
}
